<?php
//namespace student\controller\welcome;
defined('BASEPATH') OR exit('No direct script access allowed');

class Datahub extends CI_Controller {


	public function __construct()
	{
		parent::__construct();
		//$this->load->model('');
		$this->load->helper('url_helper');
		$this->load->model('getdatahub');
		$this->load->library('configservice');
		$this->load->library('loginservice');
		//$this->load->library('captcha');
		//session_start();
	}

    /**
    *  Datahub数据集展示
    */
	public function index()
	{
		$latest_number = $this->configservice->getLastestNumber();//条数限制
		$hot_number = $this->configservice->getHotNumber();
		$classic_number = $this->configservice->getClassicNumber();

		$latestdata = $this->getdatahub->getlatest($latest_number);//获取最新的数据
		$hotdata = $this->getdatahub->gethot($hot_number);//获取最热的数据
		$classicdata = $this->getdatahub->getclassic($classic_number);//获取经典数据

		$res_data = array('latestdata'=>$latestdata,'hotdata'=>$hotdata,'classicdata'=>$classicdata);
		$this->load->view('home/top_detaildata',$res_data);
		$this->load->view('home/datahub',$res_data);
		$this->load->view('home/bottom_detaildata',$res_data);
	}

    /**
     ** 获取详细的数据集信息
    **/
	public function getDetail()
	{
		$login_status = $this->loginservice->checklogin();
		if(!$login_status){
			redirect(base_url().'index.php/home/login/login/index', 'refresh');
			return 0;
		} 

		$id = @$_REQUEST['param']?$_REQUEST['param']:1;
		
		/*//数组转json存入数据库
		$arr = array(array("param"=>"姓名","type"=>"string","example"=>"zhanglei","desc"=>"个人姓名"),
					array("param"=>"年龄","type"=>"int","example"=>"12","desc"=>"个人年龄"));
		$input_data = json_encode($arr,JSON_UNESCAPED_UNICODE);
		$sql = "update data_info set field_name='$input_data' where id = 1";
		$res_query = $this->db->query($sql);*/

		/*$arr = array(array("张磊","18"),array("小王","30"),array("小李","36"),
					 array("张磊","18"),array("小王","30"),array("小李","36"),
					 array("张磊","18"),array("小王","30"),array("小李","36"),
					 array("张磊","18")
				);
		$input_data = json_encode($arr,JSON_UNESCAPED_UNICODE);
		$sql = "update data_info set temple='$input_data' where id = 1";
		$res_query = $this->db->query($sql);*/

		$res = $this->getdatahub->getdetail($id);//数据库获取数据集内容
		$res['label'] = explode(',',$res['label']);//数据集标签内容
		$res['field_name'] = json_decode($res['field_name'],true); //字段内容解释
		foreach($res['field_name'] as $key=>$val){
			$res['param_name'][] = $val['param']; //获取字段名
		}
		$res['temple'] = json_decode($res['temple'],true); //获取10条样例数据
		$res_data = array('data'=>$res);
		$this->load->view('home/top_detaildata',$res_data);
		$this->load->view('home/detaildata',$res_data);
		$this->load->view('home/bottom_detaildata',$res_data);
	}

}
